using System;
using UnityEngine;

public static class BMSoundHelper
{
	static BMSoundHelper()
	{
		BMSound.Instance.Initialize();
		BMSound.Instance.SetVolumeSFX(BMSoundHelper.volumeSFX);
		BMSound.Instance.SetVolumeBGM(BMSoundHelper.volumeBGM);
		AudioListener.volume = BMSoundHelper.volumeMaster;
	}

	public static bool EnableSFX
	{
		get
		{
			return BMSoundHelper.enableSFX;
		}
		set
		{
			if (BMSoundHelper.enableSFX == value)
			{
				return;
			}
			BMSoundHelper.enableSFX = value;
			PlayerPrefs.SetInt("Sound.enableSFX", (!BMSoundHelper.enableSFX) ? 0 : 1);
			PlayerPrefs.Save();
		}
	}

	public static bool EnableBGM
	{
		get
		{
			return BMSoundHelper.enableBGM;
		}
		set
		{
			if (BMSoundHelper.enableBGM == value)
			{
				return;
			}
			BMSoundHelper.enableBGM = value;
			PlayerPrefs.SetInt("Sound.enableBGM", (!BMSoundHelper.enableBGM) ? 0 : 1);
			PlayerPrefs.Save();
			if (!BMSoundHelper.enableBGM)
			{
				BMSoundHelper.StopBGMAll(true);
			}
		}
	}

	public static float VolumeMaster
	{
		get
		{
			return BMSoundHelper.volumeMaster;
		}
		set
		{
			if (BMSoundHelper.volumeMaster == value)
			{
				return;
			}
			BMSoundHelper.volumeMaster = value;
			PlayerPrefs.SetFloat("Sound.volumeMaster", BMSoundHelper.volumeMaster);
			PlayerPrefs.Save();
			AudioListener.volume = BMSoundHelper.volumeMaster;
		}
	}

	public static float VolumeSFX
	{
		get
		{
			return BMSoundHelper.volumeSFX;
		}
		set
		{
			if (BMSoundHelper.volumeSFX == value)
			{
				return;
			}
			BMSoundHelper.volumeSFX = value;
			PlayerPrefs.SetFloat("Sound.volumeSFX", BMSoundHelper.volumeSFX);
			PlayerPrefs.Save();
			BMSound.Instance.SetVolumeSFX(BMSoundHelper.volumeSFX);
		}
	}

	public static float VolumeBGM
	{
		get
		{
			return BMSoundHelper.volumeBGM;
		}
		set
		{
			if (BMSoundHelper.volumeBGM == value)
			{
				return;
			}
			BMSoundHelper.volumeBGM = value;
			PlayerPrefs.SetFloat("Sound.masterVolume", BMSoundHelper.volumeBGM);
			PlayerPrefs.Save();
			BMSound.Instance.SetVolumeBGM(BMSoundHelper.volumeBGM);
		}
	}

	public static void PlayBGM(string clipName, int channel = 0, bool loop = true, bool useFade = true)
	{
		if (BMSoundHelper.enableBGM)
		{
			BMSound.Instance.PlayBGM(clipName, BMSoundHelper.VolumeBGM, channel, loop, useFade);
		}
	}

	public static void StopBGM(int channel = 0, bool useFade = true, float fadeTime = 0.5f)
	{
		BMSound.Instance.StopBGM(channel, useFade, fadeTime);
	}

	public static void StopBGMAll(bool useFade = true)
	{
		BMSound.Instance.StopBGMAll(useFade);
	}

	public static void Play(string clipName, bool loop = false, float pitch = 1f)
	{
		if (BMSoundHelper.enableSFX)
		{
			BMSound.Instance.Play(clipName, BMSoundHelper.VolumeSFX, loop, pitch);
		}
	}

	public static void Stop(string clipName)
	{
		BMSound.Instance.Stop(clipName);
	}

	public static void StopAll()
	{
		BMSound.Instance.StopAll();
	}

	public static bool IsPlaying(string clipName)
	{
		return BMSound.Instance.IsPlaying(clipName);
	}

	public static void SetMaxChannelForClip(string clipName, int maxChn)
	{
		BMSound.Instance.SetMaxChannelForClip(clipName, maxChn);
	}

	private static bool enableSFX = PlayerPrefs.GetInt("Sound.enableSFX", 1) == 1;

	private static bool enableBGM = PlayerPrefs.GetInt("Sound.enableBGM", 1) == 1;

	private static float volumeMaster = PlayerPrefs.GetFloat("Sound.volumeMaster", 1f);

	private static float volumeSFX = PlayerPrefs.GetFloat("Sound.volumeSFX", 1f);

	private static float volumeBGM = PlayerPrefs.GetFloat("Sound.volumeBGM", 1f);
}
